const Koa = require('koa');
const static = require('koa-static');
const bodyParser = require('koa-bodyparser');
const render = require('koa-art-template');
const path = require('path');
const process = require('process');
const router = require('./router/route');
const app = new Koa();
const cors = require('koa2-cors');

app.listen(4000, () => console.log('server runing!'));

app.use(cors());
app.use(static(path.join(__dirname, './static')))

app.use(bodyParser());

// 配置art-template
render(app, {
    root: path.join(__dirname, 'views'),
    extname: '.html',
    debug: process.env.NODE_ENV !== 'production'
})

// app.use(async (ctx, next) => {
//     await ctx.render('index');
//     await next();
// })

app
    .use(async (ctx, next) => {
        console.log(ctx.url);
        await next();
    })
    .use(router.routes()) // 路由中间间
    .use(router.allowedMethods()) // 设置响应头